use std::io::{Error, ErrorKind};
use std::num::ParseIntError;


// 我们使用enum定义错误类型
enum MyErr {
    Err1,
    Err2,
    Err3
}

fn foo(i:i32) -> Result<(), MyErr> {
    match i {
        10 => Ok(()),
        20 => Err(MyErr::Err1),
        30 => Err(MyErr::Err2),
        _ => Err(MyErr::Err3)
    }
}


fn main() {

    // 手动创建错误
    let err = Error::new(ErrorKind::Other, "error");

    let str = "102d0";

    let r:Result<i32, ParseIntError> = str.parse::<i32>();
    match r {
        Ok(v) => println!("str is a number: {}", v),
        Err(e) => {
            match e {
                ParseIntError => println!("ParseIntError"),
                Other => println!("OtherError", ),
                _ => println!("other error", )
            }
        }
    }




    // match str.parse::<i32>() {
    //     Ok(v) => println!("str is a number: {}", v),
    //     Err(_) => println!("str is not a number")
    // }
}